package com.ruoyi.promotionConfig.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.promotionConfig.domain.ShareConfig;
import com.ruoyi.promotionConfig.service.IShareConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 推广分佣Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/shareConfig/shareConfig")
public class ShareConfigController extends BaseController
{
    @Autowired
    private IShareConfigService shareConfigService;

    /**
     * 查询推广分佣列表
     */
    @PreAuthorize("@ss.hasPermi('shareConfig:shareConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShareConfig shareConfig)
    {
        startPage();
        List<ShareConfig> list = shareConfigService.selectShareConfigList(shareConfig);
        return getDataTable(list);
    }

    /**
     * 导出推广分佣列表
     */
    @PreAuthorize("@ss.hasPermi('shareConfig:shareConfig:export')")
    @Log(title = "推广分佣", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShareConfig shareConfig)
    {
        List<ShareConfig> list = shareConfigService.selectShareConfigList(shareConfig);
        ExcelUtil<ShareConfig> util = new ExcelUtil<ShareConfig>(ShareConfig.class);
        util.exportExcel(response, list, "推广分佣数据");
    }

    /**
     * 获取推广分佣详细信息
     */
    @PreAuthorize("@ss.hasPermi('shareConfig:shareConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(shareConfigService.selectShareConfigById(id));
    }

    /**
     * 新增推广分佣
     */
    @PreAuthorize("@ss.hasPermi('shareConfig:shareConfig:add')")
    @Log(title = "推广分佣", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShareConfig shareConfig)
    {
        return toAjax(shareConfigService.insertShareConfig(shareConfig));
    }

    /**
     * 修改推广分佣
     */
    @PreAuthorize("@ss.hasPermi('shareConfig:shareConfig:edit')")
    @Log(title = "推广分佣", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShareConfig shareConfig)
    {
        return toAjax(shareConfigService.updateShareConfig(shareConfig));
    }

    /**
     * 删除推广分佣
     */
    @PreAuthorize("@ss.hasPermi('shareConfig:shareConfig:remove')")
    @Log(title = "推广分佣", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(shareConfigService.deleteShareConfigByIds(ids));
    }
}
